package com.woniu.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.woniu.apartment.domain.Security;
import com.woniu.apartment.service.ISecurityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安保设施Controller
 * 
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/apartment/tbsecurity")
@Api("安保设施管理")
public class SecurityController extends BaseController
{
    @Autowired
    private ISecurityService securityService;

    /**
     * 查询安保设施列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbsecurity:list')")
    @GetMapping("/list")
    @ApiOperation("安保设施分页查询")
    public TableDataInfo list(Security security)
    {
        startPage();
        List<Security> list = securityService.selectSecurityList(security);
        return getDataTable(list);
    }

    /**
     * 导出安保设施列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbsecurity:export')")
    @Log(title = "安保设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("安保设施导出")
    public void export(HttpServletResponse response, Security security)
    {
        List<Security> list = securityService.selectSecurityList(security);
        ExcelUtil<Security> util = new ExcelUtil<Security>(Security.class);
        util.exportExcel(response, list, "安保设施数据");
    }

    /**
     * 获取安保设施详细信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbsecurity:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("根据主键查询安保设施")
    @ApiImplicitParam(name = "ids", value = "用户ID", required = true, dataType = "Long")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(securityService.selectSecurityById(id));
    }

    /**
     * 新增安保设施
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbsecurity:add')")
    @Log(title = "安保设施", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加安保设施")
    public AjaxResult add(@RequestBody Security security)
    {
        return toAjax(securityService.insertSecurity(security));
    }

    /**
     * 修改安保设施
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbsecurity:edit')")
    @Log(title = "安保设施", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("更新安保设施")
    public AjaxResult edit(@RequestBody Security security)
    {
        return toAjax(securityService.updateSecurity(security));
    }

    /**
     * 删除安保设施
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbsecurity:remove')")
    @Log(title = "安保设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除安保设施")
    @ApiImplicitParam(name = "ids", value = "主键数组", required = true, dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(securityService.deleteSecurityByIds(ids));
    }
}
